package com.bank.lenovoz5;

import android.graphics.Bitmap;
import android.graphics.Rect;
import android.support.test.uiautomator.UiDevice;
import android.support.test.uiautomator.UiObject;
import android.support.test.uiautomator.UiObjectNotFoundException;
import android.support.test.uiautomator.UiSelector;
import android.text.TextUtils;
import android.util.Log;

import com.bank.ABCbank;
import com.bank.Bank;
import com.entity.PointBean;
import com.entity.User;
import com.receive.SMSReceiverSend;
import com.show.api.util.StringUtils;
import com.utils.ChatClient;
import com.utils.CodeUtils;
import com.utils.Constants;
import com.utils.FileHelper;
import com.utils.ImageView;
import com.utils.LogToFile;

import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import static android.os.SystemClock.sleep;
import static com.bank.Bank.sumMoney;
import static com.utils.ChatClient.CCBMethodName;
import static com.utils.ChatClient.C_updateBalance_W;
import static com.utils.ChatClient.ConfirmOrder;
import static com.utils.ChatClient.PAUSE;
import static com.utils.ChatClient.S_paused_C;
import static com.utils.ChatClient.addWorkTime;
import static com.utils.ChatClient.begintime;
import static com.utils.ChatClient.getmap;
import static com.utils.ChatClient.list;
import static com.utils.ChatClient.mapDelete;
import static com.utils.ChatClient.pressu;
import static com.utils.ChatClient.setDevicesLog;
import static com.utils.ChatClient.user;
import static com.utils.ChatClient.userInfo;
import static com.utils.Constants.orderBankName;
import static com.utils.ImageView.saveImg22;

/**
 * 项目名称：app
 * 类描述：Z5 9.0版本 农行5.0以上Z5脚本
 * 创建人：Administrator
 * 创建时间：2019/11/8 15:08
 * 修改人：Administrator
 * 修改时间：2019/11/8 15:08
 * 修改备注：
 */
public class Z5ABCbank {
    /***********金额键盘适配坐标************/
    private int[] keys_off;
    private int[] keys_off_k5 = {1025, 1250};
    private int[] keys_off_Z5 = {1025, 1340};
    private int[] key_point;
    private int[] key_point_Z5 = {185, 1970};
    private int[] key_point_K5 = {185, 1890};
    private int[][] num_keys;
    private int[][] num_keys_Z5 = new int[][]{
            {540, 1970},
            {185, 1500}, {540, 1500}, {890, 1500},
            {185, 1650}, {540, 1650}, {890, 1650},
            {185, 1810}, {540, 1810}, {890, 1810}};
    private int[][] num_keys_k5 = new int[][]{
            {540, 1890},
            {185, 1400}, {540, 1400}, {890, 1400},
            {185, 1570}, {540, 1570}, {890, 1570},
            {185, 1725}, {540, 1725}, {890, 1725}};

    private UiDevice mDevice;
    SMSReceiverSend sMSReceiverSend;
    Bank bank;
    static User user;

    private static String info1 = "";
    private static boolean isKHHDialog = true; //是否有大额转账的开户行弹框
    private boolean isNewU = false;//是新型U盾

    //键盘适配
    private void keyPhone() {
        switch (android.os.Build.MODEL) {
            case "Lenovo L38041"://k5pro
                key_point = key_point_K5;
                num_keys = num_keys_k5;
                keys_off = keys_off_k5;
                break;
            case "Lenovo L58041"://S5 Pro
            case "Lenovo L78011"://Z5
                key_point = key_point_Z5;
                num_keys = num_keys_Z5;
                keys_off = keys_off_Z5;
                break;
        }
    }

    public Z5ABCbank(ABCbank abCbank) throws UiObjectNotFoundException {
        bank = abCbank;
        this.mDevice = abCbank.mDevice;
        keyPhone();
        //检查usb连接状态
        while (true) {
            if (Constants.STATE_USB) {
                showMsg("开启界面监听");
                transfer();
                break;
            }
        }
    }

    //检索转账：进入转账
    public void transfer() throws UiObjectNotFoundException {
        ChatClient.begintime = System.currentTimeMillis();//开始时间
        while (true) {
            boolean isOutTime = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_12, "登陆前，检测版本更新超时", Constants.notReport);
            if (isOutTime) {
                break;
            }
            UiObject but1 = CodeUtils.getUiObject_textOrId("暂不更新", "com.yitong.mbank.psbc:id/dialog_cancel_tv");
            UiObject but3 = CodeUtils.getUiObject_textOrId("取消", "android:id/button1");
            UiObject but4 = CodeUtils.getUiObject_textOrId("继续使用", "android:id/button2");
            UiObject but5 = CodeUtils.getUiObject_textOrId("允许", "com.android.packageinstaller:id/permission_allow_button");
            try {
                if (but1.exists()) {
                    showMsg("====点掉版本更新=====");
                    but1.click();
                    break;
                } else if (but3.exists()) {
                    showMsg("=====点掉版本更新=====");
                    but3.click();
                } else if (but4.exists()) {
                    showMsg("=====点掉Root提示=====");
                    but4.click();
                } else if (but5.exists()) {
                    showMsg("=====允许获取账号信息=====");
                    but5.click();
                }
            } catch (Exception e) {
                showMsg("===查找更新弹窗控件错误===");
                break;
            }
        }
        // root手机需要点击继续使用
        UiObject keepUsing = CodeUtils.getUiObject_textOrId("继续使用", "android:id/button2");
        if (keepUsing.exists()) {
            try {
                showMsg("===root提示框取消===");
                keepUsing.click();
            } catch (UiObjectNotFoundException e) {
                e.printStackTrace();
            }
        }
        //重新启动银行app
        ChatClient.begintime = System.currentTimeMillis();//开始时间
        while (true) {
            boolean isOutTime = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_8, "检测重启超时", Constants.notReport);
            if (isOutTime) {
                break;
            }
            UiObject x = mDevice.findObject(new UiSelector().text("中国农业银行"));
            if (x.exists()) {
                showMsg("重新启动农行");
                x.click();
                sleep(ChatClient.overtime_3);
                transfer();
            }
        }
        //判定界面刷新成功点击转账按钮
        showMsg("===点击主页面转账按钮===");
        while (true) {
            boolean isOutTime = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_30, "登陆前，检测转账超时", Constants.notReport);
            if (isOutTime) {
                mDevice.click(400, 570);
                mDevice.click(400, 570);
                break;
            }
            UiObject rl_top_menu = mDevice.findObject(new UiSelector().resourceId("com.android.bankabc:id/rl_top_menu"));
            if (rl_top_menu.exists()) {
                Rect bounds = rl_top_menu.getVisibleBounds();
                if (!bounds.isEmpty()) {
                    showMsg("点击首页转账...");
                    mDevice.click(bounds.width() / 3, bounds.centerY());
                    break;
                }
            }
        }

        sleep(ChatClient.overtime_5);
        ChatClient.begintime = System.currentTimeMillis();//开始时间
        while (true) {
            boolean isOutTime = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_90, "登陆前，检测转账超时", Constants.isReport);
            if (isOutTime) {
                return;
            }
            showMsg("===登陆前，检测转账===");
            sleep(ChatClient.overtime_1);
            //转账
            mDevice.click(250, 420);
            mDevice.click(250, 420);
            showMsg("===登陆前，点击转账===");
            ChatClient.start();//开启与T端的通讯协议
            //获取账号信息
            ChatClient.begintime = System.currentTimeMillis();//开始时间
            while (true) {
                boolean isOutTime1 = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_90, "获取账号信息超时", Constants.isReport);
                if (isOutTime1) {
                    return;
                }
                if (userInfo.equals("")) {
                    ChatClient.msg("<YZF>{'header':'" + ChatClient.M_GET_BANK_LOGIN_INFO_P + "'}</YZF>");
                    sleep(ChatClient.overtime_5);
                } else {
                    user = new User();
                    String[] res = userInfo.split(" ");
                    showMsg("===用户登陆信息=====");
                    for (int i = 0; i < res.length; i++) {
                        switch (i) {
                            case 0:
                                user.setUserName(res[0]);
                                break;
                            case 1:
                                user.setPwd(res[1]);
                                break;
                            case 2:
                                user.setBankpwd(res[2]);
                                break;
                            case 3:
                                user.setUsbPayPwd(res[3]);
                                break;
                            case 4:
                                user.setUseType(res[4]);
                                break;
                            case 5:
                                user.setBankId(res[5]);
                                break;
                            case 6:
                                user.setUsePayMode(res[0].split("_")[1]);
                                //                                user.setUsePayMode("0");
                                break;
                        }
                    }
                    break;
                }
            }
            break;
        }
        Login();
    }


    //进入登录页面补充用户信息
    public void Login() {
        CCBMethodName = "Login";
        try {
            //判断是否进入登录页面
            ChatClient.begintime = System.currentTimeMillis();//开始时间
            while (true) {
                boolean isOutTime = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_30, "获取登录页面超时", Constants.notReport);
                if (isOutTime) {
                    if (!netWorkErr()) {
                        ChatClient.timer(LogToFile.getMethodName(), ChatClient.errorStr);
                        return;
                    }
                }
                UiObject login = CodeUtils.getUiObject_textOrClass("登录", "android.widget.Button");
                if (login.exists()) {
                    showMsg("进入登录页...");
                    break;
                }
            }

            UiObject username = CodeUtils.getUiObject_textOrClass("请输入手机号", "android.widget.EditText");
            if (username.exists()) {
                if (user.getUserName() != null) {
                    username.setText(user.getUserName());
                }
            }

            UiObject pwd = CodeUtils.getUiObject_textOrClass("请输入登录密码", "android.widget.EditText");
            pwd.setText(user.getPwd());
            sleep(ChatClient.overtime_2);
            showMsg("---检测登陆密码是否正确---");
            ChatClient.begintime = System.currentTimeMillis();//开始时间
            while (true) {
                boolean isOutTime = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_5, "检测重启超时", Constants.notReport);
                if (isOutTime) {
                    break;
                }
                UiObject msg = CodeUtils.getUiObject_textOrId("您的登录密码验证错误，还有5次就将锁定，请您检查后再次输入。", "android:id/message");
                if (msg.exists()) {//应该直接退出并且不会重启
                    showMsg("====登陆密码输入错误===");
                    ChatClient.timer(LogToFile.getMethodName(), "登陆密码错误");
                    return;
                }
            }
            //登录
            while (true) {
                UiObject mBT_login = CodeUtils.getUiObject_textOrClass("登录", "android.widget.Button");
                if (mBT_login.exists()) {
                    showMsg("登录...");
                    mBT_login.click();
                    break;
                }
            }
            mDevice.click(540, 1385);
            sleep(ChatClient.overtime_1);
            ChatClient.begintime = System.currentTimeMillis();//开始时间
            while (true) {
                boolean isOutTime = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_5, "登录页面超时", Constants.notReport);
                if (isOutTime) {
                    break;
                }
                UiObject login = CodeUtils.getUiObject_textOrClass("登录", "android.widget.Button");
                if (login.exists()) {
                    login.click();
                    sleep(ChatClient.overtime_2);
                    break;
                }
            }
            /*******查看是否有弹窗**********/
            UiObject uiObject = CodeUtils.getUiObject_textOrClass("暂不开通", "android.widget.Button");
            showMsg("===检测暂不开通===");
            if (uiObject.exists()) {
                uiObject.click();
                showMsg("===点掉了暂不开通===");
            }
            sleep(ChatClient.overtime_2);
            //登录后附言确认
            ChatClient.begintime = System.currentTimeMillis();//开始时间
            //判定转账界面是否生成
            while (true) {
                boolean isOutTime = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_90, "检测界面生成超时", Constants.isReport);
                if (isOutTime) {
                    return;
                }
                UiObject ok = CodeUtils.getUiObject_textOrId("账号转账", "com.android.bankabc:id/h5_tv_title");
                if (ok.exists()) {
                    ChatClient.loginS();
                    break;
                }
            }
            sleep(ChatClient.overtime_3);
            setRemittance();
        } catch (UiObjectNotFoundException e) {
            showMsg("----登陆异常信息---" + e.toString());
            setDevicesLog(e.getCause().getMessage());
            ChatClient.timer(LogToFile.getMethodName(), ChatClient.errorStr);
            e.printStackTrace();
        }
    }


    /**
     * 登录成功后进入转账
     *
     * @throws UiObjectNotFoundException
     */
    public void setRemittance() {
        CCBMethodName = "setTimerun";
        try {
            while (true) {
                //                sleep(ChatClient.overtime_2);
                //                Intent intent = new Intent();
                //                intent.setClass(context, MainActivity.class);
                //                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                //                intent.putExtra("bank_name", Bank.BANK_NAME);
                //                context.startActivity(intent);
                //                sleep(ChatClient.overtime_3);
                //                mDevice.pressHome();
                //                mDevice.pressHome();
                //                //启动银行app
                //                UiObject x = mDevice.findObject(new UiSelector().text(Bank.BANK_NAME));
                //                showMsg("进入" + Bank.BANK_NAME + "银行");
                //                x.click();
                //判断是否存在订单
                if (ChatClient.existOrder()) {
                    orderBankName = Constants.getBank(list.get(0).getBankName(), "ABC");
                    if (ConfirmOrder) {//T端之前账单待确认
                        //查账
                        showMsg("----开始查账---");
                        auditOrder();
                    } else {//T端无待确认状态账单直接转账
                        showMsg("----开始转账---");
                        remittanceLongin();
                    }
                } else {
                    if (PAUSE) {
                        setTimerun();
                    } else {
                        S_paused_C();
                        sleep(ChatClient.overtime_1);
                    }
                }
            }
        } catch (UiObjectNotFoundException e) {
            showMsg("----转账异常信息---" + e.toString());
            setDevicesLog(e.getCause().getMessage());
            ChatClient.timer(LogToFile.getMethodName(), ChatClient.errorStr);
            e.printStackTrace();
        }
    }


    /**
     * 跨行转账汇款
     */
    public void remittanceLongin() {
        try {
            sleep(ChatClient.overtime_1);
            CCBMethodName = "remittanceLongin";
            //获取TextView的第7个实例---余额
            while (true) {
                UiObject mTV_moeny = mDevice.findObject(new UiSelector().className("android.view.View").index(10));
                if (mTV_moeny.exists()) {
                    sumMoney = replaceMoney(CodeUtils.getUiObject_content(mTV_moeny));
                    showMsg("本地保存余额:" + sumMoney);
                    String sumMoneyFile = user.getUserName() + bank.BANK_FLAG + "_sumMoney.txt";
                    FileHelper.saveMoneySDFile(false, sumMoney, sumMoneyFile);
                    break;
                }
            }

            //账户余额是否大于转账金额
            if (Double.parseDouble(sumMoney) < Double.parseDouble(list.get(0).getMoney())) {
                ChatClient.reportTransferOrder(bank.BANK_NAME, "账户余额不足", sumMoney, 1);
                //返回上页
                mDevice.pressBack();
                ChatClient.begintime = System.currentTimeMillis();//开始时间
                while (true) {
                    boolean isOutTime = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_90, "未反回收款账户页面", Constants.isReport);
                    if (isOutTime) {
                        return;
                    }
                    UiObject zhuanzhang = CodeUtils.getUiObject_textOrClass("手机号转账", "android.view.View");
                    if (zhuanzhang.exists()) {
                        showMsg("以退出转账页...");
                        sleep(ChatClient.overtime_1);
                        break;
                    }
                }
                //转账
                mDevice.click(150, 450);
                return;
            }

            ChatClient.begintime = System.currentTimeMillis();//开始时间
            while (true) {
                boolean isOutTime = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_90, "未进入订单填充界面", Constants.isReport);
                if (isOutTime) {
                    return;
                }
                netWorkErr();
                UiObject bankNo = CodeUtils.getUiObject_textOrClass("请输入账号", "android.widget.EditText");
                if (bankNo.exists()) {
                    bankNo.click();
                    showMsg("填入银行卡号");
                    sleep(ChatClient.overtime_1);
                    bankNo.setText(list.get(0).getBankNo());
                    sleep(ChatClient.overtime_1);
                    break;
                }
            }
            mDevice.click(540, 1000);
            sleep(ChatClient.overtime_1);
            ChatClient.begintime = System.currentTimeMillis();//开始时间
            while (true) {
                boolean isOutTime = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_90, "转账汇款界面超时", Constants.isReport);
                if (isOutTime) {
                    return;
                }
                /*******开始填充转账表单*********/
                UiObject username = CodeUtils.getUiObject_textOrClass("请输入名称", "android.widget.EditText");
                if (username.exists()) {
                    showMsg("填入姓名");
                    username.click();
                    sleep(ChatClient.overtime_2);
                    username.setText(list.get(0).getUserName());
                    break;
                }
            }
            sleep(ChatClient.overtime_1);

            ChatClient.begintime = System.currentTimeMillis();//开始时间
            while (true) {
                boolean isOutTime = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_60, "订单页面超时1", Constants.isReport);
                if (isOutTime) {
                    return;
                }
                UiObject mET_money = CodeUtils.getUiObject_textOrClass("请输入转账金额", "android.view.View");
                if (mET_money.exists()) {
                    mET_money.click();
                    sleep(ChatClient.overtime_2);
                    clickMoney();
                    showMsg("关闭键盘");

                    mDevice.click(keys_off[0], keys_off_k5[1]);
                    break;
                }
            }

            ChatClient.begintime = System.currentTimeMillis();//开始时间
            while (true) {
                boolean isOutTime = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_5, "自动识别银行名", Constants.notReport);
                if (isOutTime) {
                    break;
                }
                UiObject click0 = CodeUtils.getUiObject_containTextOrClass("请选择银行", "android.view.View");
                if (click0.exists()) {
                    showMsg("点击进入选择银行");
                    click0.click();
                    if (selectBankName()) {
                        sleep(ChatClient.overtime_1);
                        break;
                    } else {
                        return;
                    }
                }
            }

            //进入下一步
            sleep(ChatClient.overtime_5);
            ChatClient.begintime = System.currentTimeMillis();//开始时间
            while (true) {
                boolean isOutTime = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_10, "下一步超时", Constants.notReport);
                if (isOutTime) {
                    showMsg("坐标点击下一步");
                    mDevice.click(540, 1940);
                    break;
                }
                UiObject mTV_next = CodeUtils.getUiObject_textOrClass("下一步", "android.widget.Button");
                if (mTV_next.exists()) {
                    showMsg("====下一步===");
                    sleep(2000);
                    /***************二次匹配下一步按钮点击***********************/
                    mTV_next = mDevice.findObject(new UiSelector().descriptionContains("下一步").className("android.widget.Button"));
                    if (mTV_next.exists()) {
                        showMsg("====点击下一步1===");
                        mTV_next.click();
                        break;
                    }
                }
            }
            //账户相同 点击下一步失败弹窗
            ChatClient.begintime = System.currentTimeMillis();//开始时间
            while (true) {
                boolean isOutTime = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_8, "弹框检测超时", Constants.notReport);
                if (isOutTime) {
                    break;
                }
                String dialog_msage = CodeUtils.getUiObject_text("android.widget.TextView", "com.alipay.mobile.antui:id/message");
                UiObject but = CodeUtils.getUiObject_textOrId("确定", "com.alipay.mobile.antui:id/ensure");
                if (!StringUtils.isEmpty(dialog_msage)) {
                    showMsg("----检测到弹框信息----" + dialog_msage);
                    if (isErrorInfo(dialog_msage)) { //检测账户相同的弹框
                        sendUnBankInfo(dialog_msage);
                        //删除处理过的订单
                        mapDelete(list.get(0).getOrder());
                        getmap();
                    }
                    //错误提示弹窗点击返回上一页面,再次进入
                    if (but.exists()) {
                        but.click();
                        sleep(ChatClient.overtime_1);
                        back();
                        sleep(ChatClient.overtime_1);
                        mDevice.click(180, 420);
                        return;
                    }
                }
            }
            //是否需要确定开户行信息流程
            if (isOverMax(list.get(0).getMoney())) {
                /**
                 * 非工作时间转账
                 */
                ChatClient.begintime = System.currentTimeMillis();//开始时间
                while (true) {
                    sleep(ChatClient.overtime_2);
                    boolean isOutTime = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_10, "非工作时间转账弹窗检测超时", Constants.notReport);
                    if (isOutTime) {
                        break;
                    }
                    UiObject maxDialog = CodeUtils.getUiObject_textOrId
                            ("您的转账超过了此时段实时处理的金额限制（不超过5万），本次转账将转人工处理。处理前不会扣款，请保持账户余额充足，并避免重复提交。人工处理时间一般为一个工作日，以最终处理时间为准。您确定提交吗？",
                                    "android:id/message");
                    UiObject sure = mDevice.findObject(new UiSelector().resourceId("android:id/button1").className("android.widget.Button"));
                    showMsg("查找非工作时间转账弹窗");
                    if (maxDialog.exists()) {
                        info1 = "非工作时间段大额预约处理," + maxDialog.getText();
                        ChatClient.reportTransferOrder(bank.BANK_NAME, info1, sumMoney, 6);
                        sure.click();
                        break;
                    }
                }
                //得到开户行信息
                showMsg("开户行信息");
                String[] array = list.get(0).getBankAdr().split("-");
                List<String> bankInfo = new ArrayList<>();
                String s = "";
                for (int i = 0; i < array.length; i++) {
                    if (i < 2) {
                        bankInfo.add(array[i]);
                    } else {
                        if (array.length == 3) {
                            bankInfo.add(array[i]);
                        } else {
                            showMsg("---开户行截取超过3---");
                            if (i == 2) {
                                s += array[i];
                            } else {
                                s += "-" + array[i];
                            }
                            showMsg("---拼接开户行后面的字段---");
                            if (i == array.length - 1) {
                                showMsg("---拼接完成---");
                                bankInfo.add(s);
                            }
                        }
                    }
                }
                sleep(ChatClient.overtime_2);
                showMsg("===准备进入选择省份===");
                setBankInfo(bankInfo);//大于5W会弹出确定开户行信息
            } else {//开始转账验证
                setBankInfo(null);
            }
        } catch (UiObjectNotFoundException e) {
            setDevicesLog(e.getMessage());
            ChatClient.timer(LogToFile.getMethodName(), ChatClient.errorStr);
            e.printStackTrace();
        }
    }

    /**
     * 输入金额
     */
    private void clickMoney() {
        for (char c : list.get(0).getMoney().toCharArray()) {
            String s = String.valueOf(c);
            if (s.equals(".")) {
                mDevice.click(key_point[0], key_point[1]);
            } else {
                int[] num_xy = num_keys[Integer.valueOf(s)];
                mDevice.click(num_xy[0], num_xy[1]);
            }
            sleep(500);
        }
    }

    /**
     * 选择银行名
     *
     * @return
     * @throws UiObjectNotFoundException
     */
    private boolean selectBankName() throws UiObjectNotFoundException {
        mDevice.drag(15, 500, 15, 1000, 30);
        ChatClient.begintime = System.currentTimeMillis();//开始时间
        while (true) {
            boolean isOutTime = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_15, "进入银行名选择超时", Constants.notReport);
            if (isOutTime) {
                ChatClient.timer(LogToFile.getMethodName(), ChatClient.errorStr);
                return false;
            }
            //在搜索栏搜索所需银行
            UiObject click = CodeUtils.getUiObject_textOrClass("搜索", "android.widget.EditText");
            if (click.exists()) {
                showMsg("填入搜索银行名...");
                click.setText(orderBankName);
                break;
            }
        }
        sleep(2000);
        //选择银行
        ChatClient.begintime = System.currentTimeMillis();//开始时间
        while (true) {
            boolean isOutTime = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_15, "银行名错误", Constants.notReport);
            if (isOutTime) {
                ChatClient.reportTransferOrder(bank.BANK_NAME, "银行名错误", sumMoney, 1);
                //返回上页
                mDevice.pressBack();
                sleep(ChatClient.overtime_3);
                mDevice.pressBack();
                sleep(ChatClient.overtime_3);
                clickTransfer();
                return false;
            }
            //搜索出的银行条目
            UiObject click0 = CodeUtils.getUiObject_textOrClass(orderBankName, "android.view.View");
            if (click0.exists()) {
                showMsg("点击---" + orderBankName);
                click0.click();
                break;
            }
        }
        return true;
    }

    /**
     * 通过U盾进行转账
     */
    private void UNextStep() throws UiObjectNotFoundException {
        CCBMethodName = "Submit";
        //确认转账
        setNext();
        addWorkTime(ChatClient.overtime_90);
        sleep(ChatClient.overtime_3);
        boolean isNotPaw = false;//是否是免密登录
        while (true) {
            UiObject editText = mDevice.findObject(new UiSelector().text("8位密码").className("android.widget.EditText"));
            UiObject editText1 = mDevice.findObject(new UiSelector().text("请输入8位密码").className("com.ronganchina.rakeyboard.RAPasswodEdit"));
            UiObject editLable1 = mDevice.findObject(new UiSelector().textContains("请输入K宝密码").className("android.widget.TextView"));
            showMsg("----检测U盾输入密码框----");

            if (editText.exists() || editLable1.exists()) {
                if (editText.exists()) {
                    editText.click();
                } else {
                    mDevice.click(520, 1000);
                }
                isNewU = false;
                showMsg("===点击密码输入框1===");
                break;
            } else if (editText1.exists()) {
                if (editText1.exists()) {
                    editText1.click();
                } else {
                    mDevice.click(570, 360);
                }
                isNewU = true;
                showMsg("===点击密码输入框2===");
                break;
            }
            showMsg("----检测U盾提示信息----");
            UiObject upwd2 = CodeUtils.getUiObject_containTextOrClass("K宝屏显翻转", "android.widget.TextView");
            UiObject upwd3 = CodeUtils.getUiObject_textOrClass("请核对K宝显示的内容是否正确，如确认请按“OK”键（或“√”键），取消请按“C”键（或“×”键）", "android.widget.TextView");
            UiObject upwd5_1 = CodeUtils.getUiObject_textOrClass("请核对K宝显示内容，如确认请按K宝的[OK]键，取消请按K宝的[C]键。", "android.widget.TextView");
            if (!upwd5_1.exists()) {
                upwd5_1 = mDevice.findObject(new UiSelector().textContains("请核对K宝显示内容").className("android.widget.TextView"));
            }
            if (upwd2.exists() || upwd3.exists() || upwd5_1.exists()) {
                showMsg("===免密码转账===");
                isNotPaw = true;
                break;
            }
            showMsg("----检测确认转账----");
            UiObject ok = mDevice.findObject(new UiSelector().text("确定").className("android.widget.Button"));
            UiObject ok1 = mDevice.findObject(new UiSelector().text("确认转账").className("android.widget.Button"));
            UiObject zhuanzhang = CodeUtils.getUiObject_textOrClass("继续转账", "android.widget.Button");
            if (ok1.exists()) {
                showMsg("----未检测U盾输入密码框----");
                ok1.click();
                addWorkTime(ChatClient.overtime_20);
                sleep(ChatClient.overtime_1);
                showMsg("===未检测到U盾再来===");
                setNext();
            } else if (ok.exists()) {
                ok.click();
                showMsg("===点击确认===");
            } else if (zhuanzhang.exists()) {
                showMsg("===发现继续转账===");
                break;
            }
        }
        CCBMethodName = "Re_send";
        //U盾密码输入
        if (!isNotPaw) {
            setUpwd();
            showMsg("---检测是否U盾密码输入正确----");
            ChatClient.begintime = System.currentTimeMillis();//开始时间
            while (true) {
                boolean isOutTime = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_5, "检测是否U盾密码输入正确超时", Constants.notReport);
                if (isOutTime) {
                    break;
                }
                UiObject u_pwd = CodeUtils.getUiObject_textOrClass("K宝密码错误，您还有5次重试机会", "android.widget.TextView");
                if (u_pwd.exists()) {
                    showMsg("---U盾输入密码错误----");
                    sendUErrorInfo("U盾密码输入错误");
                    return;
                }
            }
        } else {
            showMsg("---免密点击U盾----");
            sleep(ChatClient.overtime_3);
            pressu("2");
            isNotPaw = false;
        }
        ChatClient.begintime = System.currentTimeMillis();//开始时间
        while (true) {
            boolean isOutTime = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_40, "结果页超时", Constants.isReport);
            if (isOutTime) {
                return;
            }
            UiObject zhuanzhang = CodeUtils.getUiObject_containTextOrClass("继续转账", "android.view.View");
            UiObject ok = CodeUtils.getUiObject_textOrClass("确定", "android.widget.Button");
            UiObject back = CodeUtils.getUiObject_textOrClass("返回", "android.widget.Button");
            if (zhuanzhang.exists()) {
                sleep(ChatClient.overtime_1);
                break;
            } else if (ok.exists()) {//todo
                sleep(ChatClient.overtime_1);
                ok.click();
                addWorkTime(ChatClient.overtime_20);
                sleep(ChatClient.overtime_1);
                showMsg("===未检测到U盾===");
                setNext();
                sleep(ChatClient.overtime_1);
                setUpwd();
                ChatClient.begintime = System.currentTimeMillis();//开始时间
            } else if (back.exists()) {
                back.click();
                sleep(ChatClient.overtime_1);
                sendFailInfo("交易失败");
                return;
            }
        }
    }

    /**
     * 密码验证
     */
    private void pwdNextStep() throws UiObjectNotFoundException {
        ChatClient.begintime = System.currentTimeMillis();//开始时间
        while (true) {
            boolean isOutTime = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_40, "密码输入框超时", Constants.isReport);
            if (isOutTime) {
                return;
            }
            UiObject mV_pwd_title = CodeUtils.getUiObject_textOrId("请输入账户密码", "div_pwd_title");
            if (mV_pwd_title.exists()) {
                showMsg("进入密码验证...");
                break;
            }
        }
        int key_top = 1368;
        if (bank.carrier.contains("Lenovo L78011")) {
            key_top = 1455;
        }
        List<PointBean> pwd_key_xy = get_pwd_Key_XY(bank.BANK_FLAG + "QUICK");
        for (char c : user.getBankpwd().toCharArray()) {
            for (PointBean point_xy : pwd_key_xy) {
                if (point_xy.getCharStr().equals(String.valueOf(c))) {
                    int y = key_top + point_xy.getY();
                    if (y > 2015) y = 2015;
                    showMsg("点击密码----" + point_xy.getCharStr() + "----" + point_xy.getX() + "-----" + y);
                    mDevice.click(point_xy.getX(), y);
                    sleep(ChatClient.overtime_1);
                    break;
                }
            }
        }
        errHandle();
    }


    /**
     * 密码转账键盘截图
     */
    public List<PointBean> get_pwd_Key_XY(String bankname) {
        List<PointBean> pointBeanList;
        Bitmap bitmap = null;
        if (bank.carrier.contains("Lenovo L38041")) {
            showMsg("截图K5密码键盘");
            bitmap = ImageView.getImage1(0, 1368, 1080, 2016, 1080, 648);
        } else if (bank.carrier.contains("Lenovo L78011")) {
            showMsg("截图Z5密码键盘");
            bitmap = ImageView.getImage1(0, 1455, 1080, 2090, 1080, 635);
        } else {

        }

        pointBeanList = saveImg22(bitmap, bankname);
        return pointBeanList;
    }


    /**
     * 密码验证错误处理
     */
    private void errHandle() throws UiObjectNotFoundException {
        ChatClient.begintime = System.currentTimeMillis();//开始时间
        while (true) {
            boolean isOutTime = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_8, "密码输入框超时", Constants.notReport);
            if (isOutTime) {
                return;
            }
            UiObject mTV_pwd_err = CodeUtils.getUiObject_textOrId("密码错误", "com.alipay.mobile.antui:id/message");
            if (mTV_pwd_err.exists()) {
                showMsg("密码验证错误，重新验证...");
                UiObject mTV_pwd_err_close = CodeUtils.getUiObject_textOrId("确定", "com.alipay.mobile.antui:id/ensure");
                if (mTV_pwd_err_close.exists()) {
                    mTV_pwd_err_close.click();
                    sleep(ChatClient.overtime_1);
                    pwdNextStep();
                    break;
                }
            }
        }
    }

    /**
     * 发送U盾错误信息
     **/
    private void sendUErrorInfo(String s) {
        sendUnBankInfo(s);
        //删除处理过的订单
        mapDelete(list.get(0).getOrder());
        getmap();
        showMsg("--删除订单--");
        sleep(ChatClient.overtime_1);
        ChatClient.timer("reason", s);
    }

    /**
     * 发送错误信息
     **/
    private void sendFailInfo(String s) {
        sendUnBankInfo(s);
        sleep(ChatClient.overtime_3);
        ChatClient.begintime = System.currentTimeMillis();
        while (true) {
            boolean isOutTime = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_60, "检测收款账户超时", Constants.isReport);
            if (isOutTime) {
                return;
            }
            UiObject zhuanzhang = CodeUtils.getUiObject_textOrClass("手机号转账", "android.view.View");
            if (zhuanzhang.exists()) {
                showMsg("--检测到手机号转账--");
                sleep(ChatClient.overtime_1);
                break;
            }
        }
        mDevice.click(180, 460);
        mDevice.click(180, 460);
        showMsg("--再次转账--");
    }

    /**
     * 设置开户行信息
     *
     * @param array
     */
    private void setBankInfo(List<String> array) throws UiObjectNotFoundException {
        addWorkTime(ChatClient.overtime_30);
        //检测开户行弹窗
        if (array != null) {
            checkCity(array);
        }
        //        if (!isKHHDialog) {
        //汇款的后续流程
        ChatClient.begintime = System.currentTimeMillis();//开始时间
        while (true) {
            boolean isOutTime = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_5, "无同订单提示", Constants.notReport);
            if (isOutTime) {
                break;
            }
            UiObject mV = mDevice.findObject(new UiSelector().descriptionContains("温馨提示").className("android.view.View"));
            if (mV.exists()) {
                showMsg("温馨提示");
                UiObject mBT = mDevice.findObject(new UiSelector().descriptionContains("确定").className("android.widget.Button"));
                if (mBT.exists()) {
                    showMsg("点击确定关闭弹窗");
                    mBT.click();
                    break;
                }
            }
        }
        if (user.getUsePayMode().equals("0")) {//U盾认证
            showMsg("U盾认证");
            UNextStep();
            getUserInfo(sumMoney);
        } else {//密码验证
            showMsg("支付密码认证");
            while (true) {
                UiObject mBT = CodeUtils.getUiObject_textOrClass("确认", "android.widget.Button");
                if (mBT.exists()) {
                    showMsg("确认信息...");
                    mBT.click();
                    sleep(ChatClient.overtime_2);
                    break;
                }
            }
            pwdNextStep();
            getUserInfo(sumMoney);
        }
        //        }
    }


    /**
     * 检测是否有开户行弹窗
     *
     * @param array
     */
    private void checkCity(List<String> array) throws UiObjectNotFoundException {
        showMsg("=======检测是否有开户行弹窗========");
        ChatClient.begintime = System.currentTimeMillis();
        while (true) {
            boolean isOutTime = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_8, "检测是否弹出开户行超时", false);
            if (isOutTime) {
                isKHHDialog = false;
                return;
            }
            UiObject text = mDevice.findObject(new UiSelector().text("请尽量下拉选择开户网点，否则交易将无法实时受理").className("android.widget.TextView"));
            showMsg("检测是否弹出开户行");
            //设置开户省
            if (text.exists()) {
                UiObject frameLayout, layout1, view, view1, view6, view2;
                frameLayout = mDevice.findObject(new UiSelector().className("android.widget.FrameLayout").index(0));
                layout1 = frameLayout.getChild(new UiSelector().className("android.widget.LinearLayout").index(0));
                view = layout1.getChild(new UiSelector().className("android.view.ViewGroup").index(1));
                view1 = view.getChild(new UiSelector().className("android.view.ViewGroup").index(0));
                view6 = view1.getChild(new UiSelector().className("android.view.ViewGroup").index(0));
                view2 = view6.getChild(new UiSelector().className("android.view.ViewGroup").index(2));
                showMsg("检测开户省");
                if (view2.exists()) {
                    view2.click();
                    showMsg("找到开户省");
                    break;
                }
            }
            sleep(ChatClient.overtime_2);
        }
        sleep(ChatClient.overtime_2);
        ChatClient.begintime = System.currentTimeMillis();
        while (true) {
            sleep(ChatClient.overtime_2);
            boolean isOutTime = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_20, "检测搜索到开户省超时", false);
            if (isOutTime) {
                break;
            }
            UiObject etSearch = mDevice.findObject(new UiSelector().text("搜索").resourceId("com.android.bankabc:id/edt_search"));
            showMsg("是否搜索到开户省");
            if (etSearch.exists()) {
                etSearch.setText(array.get(0));
                showMsg("设置开户省----" + array.get(0));
                break;
            } else {
                showMsg("未找到搜索框----" + array.get(0));
            }
        }
        sleep(ChatClient.overtime_2);
        ChatClient.begintime = System.currentTimeMillis();
        while (true) {
            sleep(ChatClient.overtime_2);
            boolean isOutTime = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_20, "检测是否搜索到开户省超时", false);
            if (isOutTime) {
                break;
            }
            UiObject list = mDevice.findObject(new UiSelector().className("android.widget.ListView").resourceId("com.android" +
                    ".bankabc:id/lv_title_list"));
            showMsg("是否搜索到开户省");
            if (list.exists()) {
                UiObject item = mDevice.findObject(new UiSelector().className("android.widget.RelativeLayout").resourceId("com.android" +
                        ".bankabc:id/layout_item"));
                if (item.exists()) {
                    showMsg("搜索到开户省");
                    item.click();
                    break;
                } else {
                    showMsg("未找到开户省");
                }
            } else {
                showMsg("未找到开户省的list");
            }
        }
        sleep(ChatClient.overtime_2);
        ChatClient.begintime = System.currentTimeMillis();
        //设置开户城市
        while (true) {
            sleep(ChatClient.overtime_2);
            boolean isOutTime = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_20, "检测检测开户城市超时", false);
            if (isOutTime) {
                break;
            }
            UiObject text = mDevice.findObject(new UiSelector().text("请尽量下拉选择开户网点，否则交易将无法实时受理").className("android.widget.TextView"));
            if (text.exists()) {
                UiObject view, view1, view6, view2, frameLayout, layout1;
                frameLayout = mDevice.findObject(new UiSelector().className("android.widget.FrameLayout").index(0));
                layout1 = frameLayout.getChild(new UiSelector().className("android.widget.LinearLayout").index(0));
                view = layout1.getChild(new UiSelector().className("android.view.ViewGroup").index(1));
                view1 = view.getChild(new UiSelector().className("android.view.ViewGroup").index(0));
                view6 = view1.getChild(new UiSelector().className("android.view.ViewGroup").index(0));
                view2 = view6.getChild(new UiSelector().className("android.view.ViewGroup").index(4));
                showMsg("检测开户城市");
                if (view2.exists()) {
                    showMsg("找到开户城市");
                    view2.click();
                    break;
                }
            }
        }
        sleep(ChatClient.overtime_2);
        ChatClient.begintime = System.currentTimeMillis();
        while (true) {
            sleep(ChatClient.overtime_2);
            boolean isOutTime = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_20, "检测是否搜索到开户城市超时", false);
            if (isOutTime) {
                break;
            }
            UiObject etSearch = mDevice.findObject(new UiSelector().text("搜索").resourceId("com.android.bankabc:id/edt_search"));
            showMsg("是否搜索到开户城市");
            if (etSearch.exists()) {
                etSearch.setText(array.get(1));
                showMsg("设置开户城市");
                break;
            }
        }
        sleep(ChatClient.overtime_2);
        ChatClient.begintime = System.currentTimeMillis();
        while (true) {
            sleep(ChatClient.overtime_2);
            boolean isOutTime = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_20, "检测是否搜索到开户省超时", false);
            if (isOutTime) {
                break;
            }
            UiObject list = mDevice.findObject(new UiSelector().className("android.widget.ListView").resourceId("com.android" +
                    ".bankabc:id/lv_title_list"));
            showMsg("是否搜索到开户省");
            if (list.exists()) {
                UiObject item = mDevice.findObject(new UiSelector().className("android.widget.RelativeLayout").resourceId("com" +
                        ".android.bankabc:id/layout_item"));
                if (item.exists()) {
                    showMsg("搜索到开户省");
                    item.click();
                    break;
                }
            }
        }
        sleep(ChatClient.overtime_2);
        ChatClient.begintime = System.currentTimeMillis();
        //设置开户网点
        while (true) {
            sleep(ChatClient.overtime_2);
            boolean isOutTime = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_20, "检测检测开户网点超时", false);
            if (isOutTime) {
                break;
            }
            UiObject text = mDevice.findObject(new UiSelector().text("请尽量下拉选择开户网点，否则交易将无法实时受理").className("android.widget.TextView"));
            if (text.exists()) {
                UiObject view, view1, view6, view2, layout1, frameLayout;
                frameLayout = mDevice.findObject(new UiSelector().className("android.widget.FrameLayout").index(0));
                layout1 = frameLayout.getChild(new UiSelector().className("android.widget.LinearLayout").index(0));
                view = layout1.getChild(new UiSelector().className("android.view.ViewGroup").index(1));
                view1 = view.getChild(new UiSelector().className("android.view.ViewGroup").index(0));
                view6 = view1.getChild(new UiSelector().className("android.view.ViewGroup").index(0));
                view2 = view6.getChild(new UiSelector().className("android.view.ViewGroup").index(6));
                showMsg("检测开户网点");
                if (view2.exists()) {
                    view2.click();
                    showMsg("点击选择开户网点");
                    break;
                }
            }
        }
        sleep(ChatClient.overtime_2);
        ChatClient.begintime = System.currentTimeMillis();
        while (true) {
            sleep(ChatClient.overtime_2);
            boolean isOutTime = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_20, "检测搜索开户网点超时", false);
            if (isOutTime) {
                break;
            }
            UiObject etSearch = mDevice.findObject(new UiSelector().text("搜索").resourceId("com.android.bankabc:id/edt_search"));
            showMsg("搜索开户网点");
            if (etSearch.exists()) {
                etSearch.setText(array.get(2));
                break;
            }
        }
        sleep(2000);
        ChatClient.begintime = System.currentTimeMillis();
        while (true) {
            sleep(ChatClient.overtime_2);
            boolean isOutTime = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_20, "检测是否搜索到开户网点超时", false);
            if (isOutTime) {
                break;
            }
            UiObject listView = mDevice.findObject(new UiSelector().className("android.widget.ListView").resourceId("com.android" +
                    ".bankabc:id/lv_title_list"));
            showMsg("----是否搜索到开户网点----");
            if (listView.exists()) {
                UiObject item = mDevice.findObject(new UiSelector().className("android.widget.RelativeLayout").resourceId("com" +
                        ".android.bankabc:id/layout_item"));
                if (item.exists()) {
                    showMsg("----搜索到开户网点----");
                    item.click();
                    break;
                } else {
                    showMsg("----未搜索到开户网点----");
                    UiObject back = mDevice.findObject(new UiSelector().className("android.widget.ImageView").resourceId("com.android" +
                            ".bankabc:id/iv_back"));
                    if (back.exists()) {
                        back.click();
                        showMsg("----点击返回----");
                        sendUnBankInfo("未搜索到开户网点");
                        showMsg("===上报未搜索到开户网点====");
                        jumpOut();
                        return;
                    }
                }
            }
        }
        sleep(ChatClient.overtime_2);
        ChatClient.begintime = System.currentTimeMillis();
        while (true) {
            boolean isOutTime = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_10, "检测开户行确认超时", false);
            if (isOutTime) {
                return;
            }
            sleep(ChatClient.overtime_2);
            UiObject sure = mDevice.findObject(new UiSelector().text("确认").className("android.widget.Button"));
            showMsg("----检测开户行确认----");
            if (sure.exists()) {
                showMsg("----点击开户行确认----");
                sure.click();
                break;
            }
        }
        showMsg("----进入转账的后续流程----");
    }

    /**
     * 返回
     */
    private void jumpOut() throws UiObjectNotFoundException {
        sleep(2000);
        while (true) {
            boolean isOutTime = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_30, "查找关闭按钮超时", false);
            if (isOutTime) {
                break;
            }
            UiObject view, view1, view6, view8, view9, view10, view11, layout1;

            layout1 = mDevice.findObject(new UiSelector().className("android.widget.LinearLayout").index(0));
            view = layout1.getChild(new UiSelector().className("android.view.ViewGroup").index(1));
            view1 = view.getChild(new UiSelector().className("android.view.ViewGroup").index(0));
            view6 = view1.getChild(new UiSelector().className("android.view.ViewGroup").index(0));
            view8 = view6.getChild(new UiSelector().className("android.view.ViewGroup").index(0));
            view9 = view8.getChild(new UiSelector().className("android.view.ViewGroup").index(0));
            view10 = view9.getChild(new UiSelector().className("android.view.ViewGroup").index(0));
            view11 = view10.getChild(new UiSelector().className("android.view.ViewGroup").index(0));
            showMsg("----查找关闭按钮----");
            if (view11.exists()) {
                showMsg("----点击关闭按钮----");
                view11.click();
                break;
            }
        }
        sleep(ChatClient.overtime_2);
        while (true) {
            UiObject scroll = mDevice.findObject(new UiSelector().className("android.widget.ScrollView").index(0));
            UiObject zzView, zzView1, zzView2;
            zzView = scroll.getChild(new UiSelector().className("android.view.ViewGroup").index(0));
            zzView1 = zzView.getChild(new UiSelector().className("android.view.ViewGroup").index(0));
            zzView2 = zzView1.getChild(new UiSelector().className("android.view.ViewGroup").index(0));
            UiObject backBtn = zzView2.getChild(new UiSelector().className("android.widget.Button").index(0));
            showMsg("----查找转账页关闭按钮----");
            if (backBtn.exists()) {
                showMsg("----点击转账页关闭按钮----");
                backBtn.click();
                break;
            }
        }
        if (list.size() != 0) {
            //删除处理过的订单
            mapDelete(list.get(0).getOrder());
            getmap();
            showMsg("----删除订单----");
        }
        sleep(ChatClient.overtime_5);
        mDevice.click(525, 380); // TODO: 2019/11/11
        //转账
        showMsg("----准备再次接单----");
    }

    private void back() {
        mDevice.click(100, 145);
    }

    /**
     * 判断是否达到选择开户行的临界值
     *
     * @path sumMoney
     */
    private boolean isOverMax(String s) {
        boolean b = false;
        double c = 50000.00;//临界值为50000.00
        showMsg("===判断金额是否超过填写开户行的临界值====");
        double money = Double.parseDouble(s);
        if (money > c) {
            b = true;
        }
        showMsg("===判断金额是否超过填写开户行的临界值====" + b);
        return b;
    }

    /**
     * 完成转账后回复服务端
     *
     * @param sumMoney：余额
     */
    public void getUserInfo(String sumMoney) {
        String type = "";
        String errorStr = "";
        sleep(ChatClient.overtime_1);
        ChatClient.msg("<YZF>{'header':'" + ChatClient.M_TRANSFERFINISH_P + "'}</YZF>");
        try {
            if (isOverMax(list.get(0).getMoney())) {
                if (info1.contains("非工作时间段大额预约处理")) {
                    type = "非工作时间段大额预约处理";
                    errorStr = info1;
                }
            } else {
                type = "转账成功";
                errorStr = "转账成功";
            }
            String balance = "";
            if (Constants.getStr(type) == 0) {
                DecimalFormat formater = new DecimalFormat("#0.##");
                balance = formater.format(Double.parseDouble(sumMoney) - Double.parseDouble(list.get(0).getMoney()));
                String sumMoneyFile = user.getUserName() + bank.BANK_FLAG + "_sumMoney.txt";
                FileHelper.saveMoneySDFile(false, balance, sumMoneyFile);
            }
            errorStr = errorStr.replaceAll("\r|\n|\\s", "");
            ChatClient.reportTransferOrder(bank.BANK_NAME, errorStr, balance, Constants.getStr(type));
            sleep(ChatClient.overtime_3);
            ChatClient.begintime = System.currentTimeMillis();//开始时间
            while (true) {
                boolean isOutTime = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_60, "未查到《完成》", Constants.isReport);
                if (isOutTime) {
                    return;
                }
                UiObject click = CodeUtils.getUiObject_textOrClass("完成", "android.view.View");
                if (click.exists()) {
                    click.click();
                    break;
                }
            }
            clickTransfer();
        } catch (UiObjectNotFoundException e) {
            setDevicesLog(e.getCause().getMessage());
            ChatClient.timer(LogToFile.getMethodName(), ChatClient.errorStr);
            e.printStackTrace();
        }
    }


    private void clickTransfer() {
        ChatClient.begintime = System.currentTimeMillis();//开始时间
        while (true) {
            boolean isOutTime = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_90, "返回《转账》失败", Constants.isReport);
            if (isOutTime) {
                return;
            }
            UiObject zhuanzhang = CodeUtils.getUiObject_textOrClass("手机号转账", "android.view.View");
            if (zhuanzhang.exists()) {
                showMsg("返回转账主页...");
                sleep(ChatClient.overtime_1);
                break;
            }
        }
        //转账
        mDevice.click(180, 460);
        mDevice.click(180, 460);
        sleep(ChatClient.overtime_2);
    }

    /**
     * 查账
     *
     * @throws UiObjectNotFoundException
     */
    public void auditOrder() throws UiObjectNotFoundException {
        addWorkTime(ChatClient.overtime_40);
        showMsg("===获取余额=====");
        getBalance();
        sleep(ChatClient.overtime_1);
        mDevice.pressBack();
        sleep(ChatClient.overtime_2);
        while (true) {
            UiObject mTV_order = CodeUtils.getUiObject_textOrClass("手机号转账", "android.view.View");
            if (mTV_order.exists()) {
                showMsg("点击转账记录");
                mDevice.click(540, 800);
                sleep(ChatClient.overtime_2);
                UiObject mV_orderList = CodeUtils.getUiObject_textOrClass("转账记录", "android.view.View");
                if (mV_orderList.exists()) {
                    mV_orderList.click();
                    sleep(ChatClient.overtime_2);
                    break;
                }
            }
        }

        String name_bankNo = "";
        String money = "";
        ChatClient.begintime = System.currentTimeMillis();
        while (true) {
            boolean isOutTime = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_20, "查询超时...", Constants.notReport);
            if (isOutTime) {
                getOrderTimeOut();
                return;
            }
            UiObject mLV = mDevice.findObject(new UiSelector().className("android.widget.ListView").index(0));
            UiObject mV = mLV.getChild(new UiSelector().className("android.view.View").index(0));
            UiObject mTV_name_bankNo = mV.getChild(new UiSelector().className("android.view.View").index(1));
            UiObject mTV_money = mV.getChild(new UiSelector().className("android.view.View").index(3));
            if (mTV_name_bankNo.exists()) {
                name_bankNo = mTV_name_bankNo.getText();
                if (StringUtils.isEmpty(name_bankNo)) {
                    name_bankNo = mTV_name_bankNo.getContentDescription();
                }
            }
            if (mTV_money.exists()) {
                money = mTV_money.getText();
                if (StringUtils.isEmpty(money)) {
                    money = mTV_money.getContentDescription();
                }
            }
            if (!TextUtils.isEmpty(money)) {
                money = money.trim().replaceAll("-", "");
                money = money.trim().replaceAll(" ", "");
                money = money.trim().replaceAll(",", "");
            }
            if (!StringUtils.isEmpty(name_bankNo) && !StringUtils.isEmpty(money)) {
                showMsg("查到订单：银行卡号：" + name_bankNo + "金额：" + money);
                break;
            }
        }
        //比对数据
        if (!StringUtils.isEmpty(name_bankNo)) {
            String bankNo0 = list.get(0).getBankNo().substring(list.get(0).getBankNo().length() - 4, list.get(0).getBankNo().length());
            String bankNo = name_bankNo.substring(name_bankNo.length() - 5, name_bankNo.length() - 1);
            String state = "1";
            if (name_bankNo.contains(list.get(0).getUserName()) && Double.parseDouble(list.get(0).getMoney()) == Double.parseDouble(money) &&
                    bankNo0.equals(bankNo)) {
                state = "0";
            } else {
                String sumMoneyFile = user.getUserName() + bank.BANK_FLAG + "_sumMoney.txt";
                String oldMoney = FileHelper.readSDFile(sumMoneyFile);
                state = Constants.changeInAmount(bank.BANK_NAME, oldMoney, sumMoney, list.get(0).getMoney());
            }
            ChatClient.reportAuditOrder(state, bank);
            sleep(ChatClient.overtime_1);
        }
        //返回
        mDevice.pressBack();

        sleep(ChatClient.overtime_2);
        ChatClient.begintime = System.currentTimeMillis();//开始时间
        while (true) {
            boolean isOutTime = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_5, "登录页面超时", Constants.isReport);
            if (isOutTime) {
                return;
            }
            UiObject zhuanzhang = CodeUtils.getUiObject_textOrClass("转账", "android.widget.TextView");
            if (zhuanzhang.exists()) {
                //转账
                showMsg("点击进入转账表单");
                mDevice.click(180, 460);
                mDevice.click(180, 460);
                sleep(ChatClient.overtime_1);
                break;
            }
        }

    }

    /**
     * 查账订单超时返回
     */
    private void getOrderTimeOut() {
        ChatClient.reportAuditOrder("6", bank);
        //返回
        mDevice.pressBack();
        sleep(ChatClient.overtime_2);
        while (true) {
            UiObject zhuanzhang = CodeUtils.getUiObject_textOrClass("转账", "android.widget.TextView");
            if (zhuanzhang.exists()) {
                //转账
                showMsg("点击进入转账表单");
                mDevice.click(180, 460);
                mDevice.click(180, 460);
                sleep(ChatClient.overtime_1);
                break;
            }
        }
    }

    /**
     * 获取余额
     */
    private void getBalance() throws UiObjectNotFoundException {
        sleep(ChatClient.overtime_2);
        ChatClient.begintime = System.currentTimeMillis();//开始时间
        while (true) {
            boolean isOutTime = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_90, "转账界面获取余额超时", Constants.isReport);
            if (isOutTime) {
                return;
            }
            UiObject username = CodeUtils.getUiObject_textOrClass("请输入账号", "android.widget.EditText");
            if (username.exists()) {
                //获取余额
                UiObject moeny = mDevice.findObject(new UiSelector().className("android.view.View").index(10));
                sumMoney = replaceMoney(moeny.getContentDescription());
                showMsg("money:" + sumMoney);
                //上报余额
                C_updateBalance_W(Double.parseDouble(sumMoney));
                break;
            }
        }
    }

    /**
     * 等待订单
     *
     * @throws UiObjectNotFoundException
     */
    public void setTimerun() {
        try {
            showMsg("等待订单");
            CCBMethodName = "setTimerun";
            netWorkErr();
            ChatClient.begintime = System.currentTimeMillis();//开始时间
            while (true) {
                boolean isOutTime = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_30, "等待订单，转账界面超时", Constants.notReport);
                if (isOutTime) {
                    if (!netWorkErr()) {
                        ChatClient.timer(LogToFile.getMethodName(), ChatClient.errorStr);
                        return;
                    }
                }
                UiObject username = CodeUtils.getUiObject_textOrClass("请输入账号", "android.widget.EditText");
                if (username.exists()) {
                    //获取余额
                    UiObject mTV_moeny = mDevice.findObject(new UiSelector().className("android.view.View").index(10));
                    if (mTV_moeny.exists()) {
                        sumMoney = replaceMoney(CodeUtils.getUiObject_content(mTV_moeny));
                        showMsg("获取余额：" + sumMoney);
                        C_updateBalance_W(Double.parseDouble(sumMoney));
                        showMsg("本地保存余额");
                        String sumMoneyFile = user.getUserName() + bank.BANK_FLAG + "_sumMoney.txt";
                        FileHelper.saveMoneySDFile(false, sumMoney, sumMoneyFile);
                        break;
                    }
                }
                netWorkErr();
            }
            if (!ChatClient.waitExistOrder(ChatClient.overtime_60)) {
                mDevice.click(700, 740);
                Constants.CODE = "";
                ChatClient.request();
                sleep(ChatClient.overtime_2);
                showMsg("确定银行卡号");
                mDevice.click(990, 1330);
                sleep(ChatClient.overtime_2);
            }
        } catch (Exception e) {
            setDevicesLog(e.getCause().getMessage());
            ChatClient.timer("setTimerun", ChatClient.error);
            e.printStackTrace();
        }
    }


    /**
     * 处理网络不稳定弹窗
     */
    private boolean netWorkErr() throws UiObjectNotFoundException {
        UiObject mDialog_message = mDevice.findObject(new UiSelector().resourceId("android:id/message").textContains("网络不稳定"));
        if (mDialog_message.exists()) {
            UiObject mBT_Dialog = mDevice.findObject(new UiSelector().text("确定").resourceId("android:id/button1"));
            if (mBT_Dialog.exists()) {
                showMsg("出现网络不稳定...");
                mBT_Dialog.click();
                sleep(ChatClient.overtime_1);
                return true;
            }
        }
        return false;
    }

    /**
     * 得到可用金额
     *
     * @param str
     * @return
     */
    public static String replaceMoney(String str) {
        String money = "";
        String regxp = "((-)?(([1-9]{1}\\d*)|([0]{1}))(\\.(\\d){1,2})?)";
        str = str.replaceAll(",", "");
        Pattern p = Pattern.compile(regxp);
        Matcher m = p.matcher(str);
        while (m.find()) {
            money = m.group();
        }
        return StringUtils.isEmpty(money) ? "0.00" : money;
    }

    // U盾截去数字键盘
    public void getNum_U_all(String pwd) {
        List<PointBean> pointBeanList;
        try {
            Bitmap bitmap = null;
            bitmap = getUKeysImages();
            pointBeanList = saveImg22(bitmap, bank.BANK_FLAG);
            showMsg("pointBeanList=" + pointBeanList.size());
            setClick_U_535(pointBeanList, pwd);
        } catch (Exception e) {
            setDevicesLog(e.getCause().getMessage());
            e.printStackTrace();
        }
    }


    /**
     * 截去英文键盘模拟用户输入密码
     * U盾密码字母键盘
     *
     * @param pwd:要点击的密码
     * @throws UiObjectNotFoundException
     */
    public void getABC_U_all(String pwd) {
        List<PointBean> pointBeanList;
        try {
            Bitmap bitmap = null;
            bitmap = getUKeysImages();
            pointBeanList = saveImg22(bitmap, bank.BANK_FLAG);
            setClick_U_535(pointBeanList, pwd);
        } catch (
                Exception e) {
            setDevicesLog(e.getCause().getMessage());
            e.printStackTrace();
        }

    }

    /**
     * 模拟点击密码
     *
     * @param pad_ 要点击的
     */
    public void setClick_U_535(List<PointBean> pointBeanList, String pad_) {
        String tempStr = "";
        showMsg("pointBeanList--------->" + pointBeanList.size());
        if (pointBeanList.size() > 0) {
            for (int i = 0; i < pointBeanList.size(); i++) {
                tempStr += pointBeanList.get(i).getCharStr();
            }
        }
        showMsg("pointBeanList--------->" + pointBeanList.size());
        char[] abc_num = tempStr.toCharArray();//字母或者数字数组
        char[] pwd = pad_.toCharArray();//要点击的密码char数组
        showMsg("tempStr==" + tempStr);
        showMsg("pad_==" + pad_.length());
        int topX = 0;
        switch (android.os.Build.MODEL) {
            case "Lenovo L38041"://k5pro
                topX = 1530;
                break;
            case "Lenovo L58041"://S5 Pro
            case "Lenovo L78011"://Z5
                topX = 1620;
                break;
        }
        for (int j = 0; j < pwd.length; j++) {
            for (int i = 0; i < abc_num.length; i++) {
                if (abc_num[i] == pwd[j]) {

                    if (isNumeric(String.valueOf(pwd[j]))) {
                        sleep(ChatClient.overtime_1);
                        //点击数字
                        int num = pointBeanList.get(i).getY();
                        Log.d("U盾键盘的Y坐标：", "Y轴坐标为：-------" + num);
                        mDevice.click((pointBeanList.get(i).getX()), num + topX);
                        showMsg("点击第" + j + "位");
                    } else {
                        sleep(ChatClient.overtime_1);
                        //点击字母
                        int num = pointBeanList.get(i).getY();
                        mDevice.click((pointBeanList.get(i).getX()), num + topX);
                        showMsg("点击第" + j + "位");
                    }
                    break;
                }
            }
        }
        sleep(ChatClient.overtime_1);
    }

    /**
     * 535型号U盾密码切换
     *
     * @param pad_ U盾密码
     * @throws UiObjectNotFoundException
     */
    public void getPwd_u_all(String pad_) {
        showMsg("===识别U盾开始888=====");
        char[] pwd = pad_.toCharArray();//char数组
        String abc = splitNotNumber(pad_);
        showMsg("===U盾密码为=====");
        String num = getNumbers(pad_);
        isAbcNum();
        if (isNumeric(String.valueOf(pwd[0]))) {
            //切换数字键盘
            cutoverKeys();
            sleep(ChatClient.overtime_2);
            getNum_U_all(num);
            showMsg("===数字键盘识别完成=====");
            sleep(ChatClient.overtime_2);
            //切换字母键盘
            cutoverKeys();
            sleep(ChatClient.overtime_1);
            getABC_U_all(abc);
            showMsg("===字母键盘识别完成=====");
        } else {
            sleep(ChatClient.overtime_2);
            getABC_U_all(abc);
            showMsg("===字母键盘识别完成=====");
            //切换数字键盘
            cutoverKeys();
            sleep(ChatClient.overtime_2);
            getNum_U_all(num);
            showMsg("===数字键盘识别完成=====");
        }

    }

    /**
     * 判断字母还是数字键盘
     */
    public void isAbcNum() {
        showMsg("===U盾识别=1====");
        try {
            boolean state = false;
            ChatClient.begintime = System.currentTimeMillis();//开始时间
            while (true) {
                boolean isOutTime = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_15, "U盾识别", Constants.notReport);
                if (isOutTime) {
                    addWorkTime(ChatClient.overtime_30);
                    cutoverKeysCase();
                    sleep(ChatClient.overtime_1);
                    ChatClient.begintime = System.currentTimeMillis();//开始时间
                    showMsg("===字母转换大写=====");
                }
                if (!state) {
                    List<PointBean> pointBeanList;
                    sleep(ChatClient.overtime_1);
                    Bitmap bitmap = getUKeysImages();
                    showMsg("=== saveImg22====");
                    pointBeanList = saveImg22(bitmap, bank.BANK_FLAG);
                    String tempStr = "";
                    if (pointBeanList.size() > 0) {
                        state = true;
                        for (int i = 0; i < pointBeanList.size(); i++) {
                            tempStr += pointBeanList.get(i).getCharStr();
                        }
                        showMsg("===识别结果键盘=====" + tempStr);
                        char[] abc_num = tempStr.toCharArray();//字母或者数字数组
                        String num = String.valueOf(abc_num[0]);
                        if (isNumeric(num)) {
                            cutoverKeys(); //切换数字键盘
                            sleep(ChatClient.overtime_1);
                            showMsg("===默认切换到字母键盘=====");
                            isAbcNum1();
                            break;
                        } else {
                            if (tempStr.contains("y") || tempStr.contains("h") || tempStr.contains("m")) {
                                showMsg("===识别结果键盘包含=====yjm");
                                cutoverKeysCase();
                                break;
                            } else if (tempStr.contains("Y") || tempStr.contains("H") || tempStr.contains("M")) {
                                break;
                            }
                        }
                    } else {
                        addWorkTime(ChatClient.overtime_30);
                        cutoverKeysCase();
                        sleep(ChatClient.overtime_1);
                        showMsg("===无法识别===11111==");
                        state = false;
                    }
                }
            }
        } catch (
                Exception e) {
            setDevicesLog(e.getCause().getMessage());
            e.printStackTrace();
        }

    }

    /**
     * 判断字母还是数字
     */
    public void isAbcNum1() {
        try {
            showMsg("===U盾识别=2====");
            boolean state1 = false;
            ChatClient.begintime = System.currentTimeMillis();//开始时间
            while (true) {
                boolean outTime = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_15, "字母转换大写...", Constants.notReport);
                if (outTime) {
                    addWorkTime(ChatClient.overtime_30);
                    cutoverKeysCase();
                    sleep(ChatClient.overtime_1);
                    ChatClient.begintime = System.currentTimeMillis();//开始时间
                }
                if (!state1) {
                    sleep(ChatClient.overtime_1);
                    List<PointBean> pointBeanList;
                    Bitmap bitmap = null;
                    bitmap = getUKeysImages();
                    pointBeanList = saveImg22(bitmap, bank.BANK_FLAG);
                    String tempStr = "";
                    if (pointBeanList.size() > 0) {
                        state1 = true;
                        for (int i = 0; i < pointBeanList.size(); i++) {
                            tempStr += pointBeanList.get(i).getCharStr();
                        }
                        showMsg("===识别结果键盘==2222===" + tempStr);
                        if (tempStr.contains("y") || tempStr.contains("h") || tempStr.contains("m")) {
                            showMsg("===识别结果键盘包含=====yjm");
                            cutoverKeysCase();
                            break;
                        } else if (tempStr.contains("Y") || tempStr.contains("H") || tempStr.contains("M")) {
                            break;
                        }
                    } else {
                        addWorkTime(ChatClient.overtime_30);
                        cutoverKeysCase();
                        sleep(ChatClient.overtime_1);
                        showMsg("===无法识别==22222===");
                        state1 = false;
                    }
                }
            }
        } catch (Exception e) {
            setDevicesLog(e.getCause().getMessage());
            e.printStackTrace();
        }
    }

    /**
     * 截取U盾键盘
     */
    private Bitmap getUKeysImages() {
        Bitmap bitmap = null;
        switch (android.os.Build.MODEL) {
            case "Lenovo L38041"://k5pro
                bitmap = ImageView.getImage1(0, 1500, 1080, 2000, 1080, 500);
                break;
            case "Lenovo L58041"://S5 Pro
            case "Lenovo L78011"://Z5
                bitmap = ImageView.getImage1(0, 1620, 1080, 2080, 1080, 460);
                break;
        }
        return bitmap;
    }


    /**
     * U盾键盘字母数字切换
     */
    private void cutoverKeys() {
        //切换数字键盘
        switch (android.os.Build.MODEL) {
            case "Lenovo L38041"://k5pro
                mDevice.click(970, 1920);
                break;
            case "Lenovo L58041"://S5 Pro
            case "Lenovo L78011"://Z5
                mDevice.click(970, 2000);
                break;
        }
    }


    /**
     * U盾键盘大小写切换
     */
    private void cutoverKeysCase() {
        //切换数字键盘
        switch (android.os.Build.MODEL) {
            case "Lenovo L38041"://k5pro
                mDevice.click(60, 1920);
                break;
            case "Lenovo L58041"://S5 Pro
            case "Lenovo L78011"://Z5
                mDevice.click(60, 2000);
                break;
        }
    }


    /**
     * 字母和数字键盘的切换
     *
     * @param checkStr
     * @return
     */
    public static boolean isNumeric(String checkStr) {
        try {
            Integer.parseInt(checkStr);
            return true;
        } catch (NumberFormatException err) {
            return false;
        }
    }

    // 截取数字
    public static String getNumbers(String content) {
        Pattern pattern = Pattern.compile("\\d+");
        Matcher matcher = pattern.matcher(content);
        while (matcher.find()) {
            return matcher.group(0);
        }
        return "";
    }

    // 截取非数字
    public static String splitNotNumber(String content) {
        Pattern pattern = Pattern.compile("\\D+");
        Matcher matcher = pattern.matcher(content);
        while (matcher.find()) {
            return matcher.group(0);
        }
        return "";
    }

    /**
     * 弹框信息判断
     */
    private boolean isErrorInfo(String s) {
        boolean b = false;
        if (s.contains("转入账户与转出账户不能相同") || s.contains("请选择收款银行")) {
            showMsg("=======银行卡号问题...=====");
            b = true;
        }
        return b;
    }

    /**
     * 输入U盾密码
     *
     * @throws UiObjectNotFoundException
     */
    public void setUpwd() throws UiObjectNotFoundException {
        UiObject zhuanzhang = CodeUtils.getUiObject_textOrClass("继续转账", "android.widget.Button");
        if (zhuanzhang.exists()) {
            return;
        }
        addWorkTime(ChatClient.overtime_20);
        ChatClient.begintime = System.currentTimeMillis();//开始时间
        while (true) {
            boolean isOutTime = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_90, "链接超时...", Constants.isReport);
            if (isOutTime) {
                return;
            }

            UiObject upwd1 = CodeUtils.getUiObject_contentText("屏显翻转");
            UiObject upwd2 = CodeUtils.getUiObject_contentText("核对K宝");
            UiObject zhuanzhangnext = CodeUtils.getUiObject_textOrClass("继续转账", "android.widget.Button");
            if (upwd1.exists()) {
                showMsg("---屏显翻转---");
                break;
            } else if (upwd2.exists()) {
                showMsg("---核对K宝---");
                break;
            } else if (zhuanzhangnext.exists()) {
                showMsg("---继续转账---");
                break;
            }
            boolean isOutTime1 = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_8, "开始输入U盾密码", Constants.notReport);
            if (isOutTime1) {
                //wb add
                sleep(2000);
                showMsg("===U盾密码输入开始===测试==");
                if (isNewU) {
                    clickUPwd(user.getUsbPayPwd());
                } else {
                    getPwd_u_all(user.getUsbPayPwd());
                }
                showMsg("===U盾密码输入完成===测试==");
                ChatClient.begintime = System.currentTimeMillis();//开始时间
                while (true) {
                    boolean isOutTime2 = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_90, "确认超时...", Constants.isReport);
                    if (isOutTime2) {
                        return;
                    }
                    UiObject upwd = CodeUtils.getUiObject_contentText("确定");
                    UiObject upwdt = mDevice.findObject(new UiSelector().index(1).className("android.widget.Button"));
                    UiObject upwdcancel = mDevice.findObject(new UiSelector().text("取消").className("android.widget.Button"));
                    if (upwdt.exists() && upwdcancel.exists()) {
                        upwdt.click();
                        showMsg("upwdt----点击确定1----");
                        break;
                    } else if (upwd.exists()) {
                        upwd.click();
                        showMsg("upwd----点击确定2----");
                        break;
                    }
                }
                sleep(ChatClient.overtime_3);
                while (true) {
                    boolean isOutTime2 = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_3, "确认超时...", Constants.notReport);
                    if (isOutTime2) {
                        break;
                    }
                    UiObject qx = mDevice.findObject(new UiSelector().text("取消").className("android.widget.Button"));
                    if (qx.exists()) {
                        qx.click();
                        sleep(ChatClient.overtime_3);
                        setUBack();
                        sleep(ChatClient.overtime_2);
                        addWorkTime(ChatClient.overtime_60);
                        showMsg("===未检测到U盾===");
                        setNext();
                        break;
                    }
                }
                break;
            }
        }
        ChatClient.msg("<YZF>{'header':'" + ChatClient.M_TRANSFERFINISH_P + "'}</YZF>");
        sleep(ChatClient.overtime_3);
        pressu("2");
    }

    /**
     * 新版U盾点击密码
     *
     * @param usbPayPwd
     */
    private void clickUPwd(String usbPayPwd) {
        showMsg("新版U盾点击密码：点击切换字母键盘");
        mDevice.click(970, 1970);
        sleep(ChatClient.overtime_3);
        showMsg("点击切换大写字母");
        mDevice.click(60, 1970);
        sleep(ChatClient.overtime_3);
        List<PointBean> pointBeanList = get_U_Key_XY(bank.BANK_FLAG + "935A");
        boolean isNum = false;
        char[] chars = usbPayPwd.toCharArray();
        int yHeight = 1602;
        if (bank.screenHeight == 2016) {
            yHeight = 1525;
        } else if (bank.screenHeight == 2102) {
            yHeight = 1602;
        }
        for (int i = 0; i < chars.length; i++) {
            String s = String.valueOf(chars[i]);
            if (isNumeric(s) && !isNum) {
                showMsg("点击切换数字键盘");
                mDevice.click(970, 1970);
                sleep(ChatClient.overtime_3);
                pointBeanList = get_U_Key_XY(bank.BANK_FLAG + "935N");
                isNum = true;
            }
            for (PointBean point : pointBeanList) {
                if (point.getCharStr().equals(s)) {
                    showMsg("点击第" + i + "位");
                    mDevice.click(15 + (point.getX()), yHeight + point.getY());
                    sleep(ChatClient.overtime_1);
                    break;
                }
            }
        }
    }


    /**
     * 新款935型U盾键盘截图
     */
    public List<PointBean> get_U_Key_XY(String bankname) {
        List<PointBean> pointBeanList;
        Bitmap bitmap = null;
        showMsg("截图新U盾键盘");
        if (bank.screenHeight == 2016) {
            showMsg("截图新U盾键盘");
            bitmap = ImageView.getImage1(15, 1525, 1055, 1983, 1040, 458);
        } else if (bank.screenHeight == 2102) {
            bitmap = ImageView.getImage1(15, 1602, 1060, 2080, 1045, 478);
        } else {

        }
        pointBeanList = saveImg22(bitmap, bankname);
        return pointBeanList;
    }

    /**
     * 确认转账
     *
     * @throws UiObjectNotFoundException
     */
    public void setNext() throws UiObjectNotFoundException {
        showMsg(">>>>>确认转账");
        //进入转账页面
        ChatClient.begintime = System.currentTimeMillis();//开始时间
        while (true) {
            boolean isOutTime = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_40, "setNext", Constants.isReport);
            if (isOutTime) {
                return;
            }
            UiObject ok = CodeUtils.getUiObject_textOrClass("确认", "android.widget.Button");
            UiObject ok1 = mDevice.findObject(new UiSelector().text("确认转账").className("android.widget.Button"));

            UiObject zhuanzhang = CodeUtils.getUiObject_textOrClass("继续转账", "android.widget.Button");

            UiObject upwd14 = CodeUtils.getUiObject_textOrClass("请核对K宝显示的内容是否正确，如确认请按“OK”键（或“√”键），取消请按“C”键（或“×”键）", "android.widget.TextView");
            UiObject upwd15 = CodeUtils.getUiObject_textOrClass("请核对K宝显示内容，如确认请按K宝的[OK]键，取消请按K宝的[C]键。", "android.widget.TextView");

            UiObject upwd5_1 = CodeUtils.getUiObject_containTextOrClass("请核对K宝显示内容", "android.widget.TextView");
            UiObject upwd8 = CodeUtils.getUiObject_containTextOrClass("K宝屏显翻转", "android.widget.TextView");

            if (ok.exists()) {
                ok.click();
                showMsg("点击确认");
                break;
            } else if (ok1.exists()) {
                ok1.click();
                showMsg("点击确认转账");
                break;
            }
            if (upwd14.exists() || upwd8.exists() || upwd15.exists() || upwd5_1.exists()) {
                sleep(ChatClient.overtime_2);
                pressu("2");
                break;
            }
            if (zhuanzhang.exists()) {
                return;
            }
        }
        showMsg(">>>>>查找继续转账");
        sleep(ChatClient.overtime_3);
        while (true) {
            UiObject zhuanzhang = CodeUtils.getUiObject_textOrClass("继续转账", "android.widget.Button");
            UiObject ProgressBar = mDevice.findObject(new UiSelector().className("android.widget.ProgressBar"));
            if (ProgressBar.exists()) {
            } else {
                showMsg(">>>>>检查U盾进度条");
                break;
            }
            if (zhuanzhang.exists()) {
                showMsg(">>>>>查继续转账");
                return;
            }
        }
        ChatClient.begintime = System.currentTimeMillis();//开始时间
        while (true) {
            boolean isOutTime = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_5, "关闭K宝链接失败弹窗超时", Constants.notReport);
            if (isOutTime) {
                break;
            }
            UiObject mTV = mDevice.findObject(new UiSelector().textContains("连接失败"));
            if (mTV.exists()) {
                showMsg("K宝链接失败");
                UiObject mBT = mDevice.findObject(new UiSelector().className("android.widget.Button").text("确定").index(0));
                if (mBT.exists()) {
                    showMsg("关闭K宝链接失败弹窗");
                    mBT.click();
                    sleep(ChatClient.overtime_2);
                    setNext();
                    break;
                }
            }
        }
        sleep(ChatClient.overtime_2);
        ChatClient.begintime = System.currentTimeMillis();//开始时间
    }

    public void setUBack() throws UiObjectNotFoundException {
        while (true) {
            UiObject ok = mDevice.findObject(new UiSelector().text("确定").className("android.widget.Button"));
            if (ok.exists()) {
                sleep(ChatClient.overtime_3);
                ok.click();
                break;
            }
        }
    }

    /**
     * 发送转账失败
     */
    private void sendUnBankInfo(String info) {
        ChatClient.reportTransferOrder(bank.BANK_NAME, info, sumMoney, 1);
    }

    public void showMsg(String msg) {
        LogToFile.showLog("农业银行", msg);
    }

}
